<?php

include_once 'Expression.php';

/**
 * Represents a scalar value
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/PrimitiveExpressionExample.php 
 */

class PrimitiveExpression extends Expression
{
    /**
     * The PrimitiveExpression constructor
     * @param mixed $value The scalar value 
     */
    
    public function __construct($value)
    {
        parent::__construct();
        $this->set_Value($value);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */    
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'Value')
        {
            $this->set_Value($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'Value')
        {
            return $this->get_Value();
        }
    }
    
    /**
     * The $Value getter method
     * @return mixed 
     */
    
    public function get_Value()
    {
        return $this->Value;
    }

    /**
     * The $Value setter method
     * @param mixed $value
     * @throws InvalidArgumentException 
     * 
     * @assert (new stdClass()) throws InvalidArgumentException
     * @assert (array(1, 2, 3)) throws InvalidArgumentException
     */
    
    public function set_Value($value)
    {
        if(is_scalar($value) || $value == null)
        {
            $this->Value = $value;
        }
        else
        {
            throw new InvalidArgumentException(
              'The expression must be a scalar value.');
        }
    }
    
    /**
     * The scalar value to be represented
     * @var mixed 
     */
    
    private $Value;
}

?>
